#include <iostream>
#include <map>
#include <string>

using namespace std;
class AuthenticationManager {
public:
    AuthenticationManager(int timeToLive) {
		this->timeToLive = timeToLive;
    }
    
    void generate(string tokenId, int currentTime) {
		idMap[tokenId] = currentTime;
    }
    
    void renew(string tokenId, int currentTime) {
		if (idMap[tokenId] == 0) {
			cout << "tokenId not exist" << endl;
			return;
		}
		if (isLive(idMap[tokenId], currentTime)) {
			idMap[tokenId] = currentTime;
		}
		return;
    }
    
    int countUnexpiredTokens(int currentTime) {
		int cnt;
		for (auto m : idMap) {
			if (isLive(m.second, currentTime)) {
				cnt++;
			}
		}
		return cnt;
    }

private:

	bool isLive(int bornTime, int currentTime) {
		int lastTime = bornTime + timeToLive;
		if (lastTime <= currentTime) {
			return false;
		}
		return true;
	}
	int timeToLive;
	map<string, int> idMap;
};

/**
 * Your AuthenticationManager object will be instantiated and called as such:
 * AuthenticationManager* obj = new AuthenticationManager(timeToLive);
 * obj->generate(tokenId,currentTime);
 * obj->renew(tokenId,currentTime);
 * int param_3 = obj->countUnexpiredTokens(currentTime);
 */
